@extends('admin/layouts/admin')
@section('title', '添加内容')
@section('main')
<div class="main-title"><h2>添加内容</h2></div>
<div class="main-section">
  <div style="width: 80%">
    <!-- 添加内容表单 -->
    <form action="{{ url('/content/save') }}" method="post" class="j-form">
      <div class="form-group row">
        <label class="col-sm-2 col-form-label">所属栏目</label>
        <div class="col-sm-10">
          <select name="cid" class="form-control" style="width:200px">
            <option value="0">---</option>
            @foreach ($category as $v)
            <option value="{{ $v['id'] }}">
              @if ($v['level']) ├── @endif {{ $v['name'] }}
            </option>
            @endforeach
          </select>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-2 col-form-label">标题</label>
        <div class="col-sm-10">
          <input type="text" name="title" class="form-control" style="width:200px">
        </div>
      </div>
      <!-- 上传图片按钮 -->
      <div class="form-group row">
        <label class="col-sm-2 col-form-label">图片</label>
        <div class="col-sm-10">
          <input type="file" id="file1" value="上传图片">
          <div class="upload-img-box" id="uploadImg"></div>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-2 col-form-label">简介</label>
        <div class="col-sm-10">
          <!-- <textarea name="content" class="j-goods-content" style="height:500px"></textarea> -->
          <script style="text/plain" class="j-goods-content" name="content" style="height:500px"></script>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-2 col-form-label">状态</label>
        <div class="col-sm-10">
          <div class="form-check form-check-inline" style="height:38px">
            <input type="radio" class="form-check-input" name="status"  id="inlineRadio1" value="1" checked>
            <label for="inlineRadio1" class="form-check-label">默认</label>
          </div>
          <div class="form-check form-check-inline" style="height:38px">
            <input type="radio" class="form-check-input" name="status"  id="inlineRadio2" value="2">
            <label for="inlineRadio2" class="form-check-label">推荐</label>
          </div>
        </div>
      </div>
      <div class="form-group row">
        <div class="col-sm-10">
          @csrf
          <button type="submit" class="btn btn-primary mr-2">提交表单</button>
          <a href="{{ url('content') }}" class="btn btn-secondary">返回列表</a>
        </div>
      </div>
    </form>
  </div>
</div>
<script src="{{asset('admin')}}/common/uploader/jquery.uploadifive.js"></script>
<script src="{{asset('admin')}}/common/editor/ueditor1.4.3.3/ueditor.config.js"></script>
<script src="{{asset('admin')}}/common/editor/ueditor1.4.3.3/ueditor.all.min.js"></script>
<script src="{{asset('admin')}}/common/editor/main.editor.js"></script>
<script>
  main.menuActive('addcontent');
  $('head').append('<link href="{{asset('admin')}}/common/uploader/uploadifive.css" rel="stylesheet">');
  $('#file1').uploadifive({
    auto: true,
    fileObjName: 'image',
    fileType: 'image',
    buttonText: '上传图片',
    formData: { _token: '{{ csrf_token() }}' },
    method: 'post',
    queueID: 'uploadImg',
    removeCompleted: true,
    uploadScript: '{{ url('content/upload') }}',
    onUploadComplete: uploadPicture
  });
  function uploadPicture(file, data) {
    var obj = $.parseJSON(data);
    if (obj.code) {
      var filename = obj.data.filename;
      var path = obj.data.path;
      $('.upload-img-box').empty();
      $('.upload-img-box').html(
        '<div class="upload-pre-item" style="min-height:100%;"><img src="' + path + '" style="width:100px;height:100px"><input type="hidden" name="image" value="' + filename + '" class="icon_banner"></div>'
      );
    } else if (data.info) {
      alert(data.info);
    } else {
      alert(data);
    }
  }
  main.editor($('.j-goods-content'), 'content_edit', function (opt) {
    opt.UEDITOR_HOME_URL = '{{asset('admin')}}/common/editor/ueditor1.4.3.3/';
  }, function (editor) {
    $('.j-form').submit(function () {
      editor.sync();
    });
  });
</script>
@endsection